﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Web.Script.Serialization;
using swaganomics.Backend;

namespace swaganomics.Metro.Dialogs
{
    /// <summary>
    /// Interaction logic for EnterData.xaml
    /// </summary>
    public partial class EnterData : Window
    {
        public EnterData(double width)
        {
            InitializeComponent();

            this.Width = width;
        }

        private void btnCompleted_Click(object sender, RoutedEventArgs e)
        { 
            JavaScriptSerializer jss = new JavaScriptSerializer(); 
             
            Backend.DataFormats.ServerInput.Input input = new Backend.DataFormats.ServerInput.Input() 
            { 
                Action = "calculate", 
                Content = new Backend.DataFormats.ServerInput.Content() 
                { 
                    Age = int.Parse(txtAge.Text),  
                    Gender = cbGender.SelectedIndex == 2 ? 0 : cbGender.SelectedIndex, 
                    YearlyIncome = double.Parse(txtYearlyIncome.Text), 
                    PacksOfCigarettes = double.Parse(txtPacksOfCigaretts.Text), 
                    LitresOfFuel = double.Parse(txtLitresOfFuel.Text), 
                    LitresOfSprits = double.Parse(txtLitresOfSpirits.Text), 
                    PintsOfBeer = double.Parse(txtPintsOfBeer.Text), 
                    MonthlyVATExpendature = double.Parse(txtVATItemsMonth.Text) 
                } 
            };

            string jsonInput = jss.Serialize(input);
            string returned = ServerConnector.GetServerResponse(jsonInput);
            Backend.Settings.homeWindow.TaxData = jss.Deserialize<Backend.DataFormats.ServerResponse.Response>(returned);
            this.Close();
        } 
    } 
}  